package com.jarchie.htgl.fragment;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;
import com.jarchie.htgl.base.BaseApp;
import com.jarchie.htgl.R;
import com.jarchie.htgl.activity.LoginActivity;
import com.jarchie.htgl.base.BaseFragment;
import com.jarchie.htgl.utils.ActivityManager;
import com.jarchie.htgl.views.CommonDialog;

/**
 * Created by Jarchie on 2017\12\12.
 * 口令管理的Fragment
 */

public class PwdManageFragment extends BaseFragment implements View.OnClickListener {
    private TextView btnLoginOut;
    private CommonDialog mCommonDialog;
    private TextView btnConfirm, btnCancel;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_pwd_manage;
    }

    @Override
    protected void initView(View rootView) {
        btnLoginOut = obtainView(R.id.btn_login_out);
        mCommonDialog = new CommonDialog(getContext(), R.layout.dialog_alert_layout);
        mCommonDialog.setCanceledOnTouchOutside(false);
        mCommonDialog.setCancelable(false);
        btnConfirm = mCommonDialog.findViewById(R.id.btn_confirm);
        btnCancel = mCommonDialog.findViewById(R.id.btn_cancel);
    }

    @Override
    protected void setListener() {
        btnLoginOut.setOnClickListener(this);
        btnConfirm.setOnClickListener(this);
        btnCancel.setOnClickListener(this);
    }

    @Override
    protected void initData() {}

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_login_out:
                mCommonDialog.show();
                break;
            case R.id.btn_confirm:
                BaseApp.getInstance().setUserLogin(null);
                startActivity(new Intent(getContext(), LoginActivity.class));
                getActivity().finish();
                ActivityManager.getInstance().finishAllActivity();
                break;
            case R.id.btn_cancel:
                mCommonDialog.cancel();
                break;
        }
    }

}
